import jenkins


class JenkinsApi:
    def __init__(self):
        jenkins_server_url = 'http://100.81.136.54:8080'
        user_id = 'admin'
        api_token = '117d7547c0f89df002bf25f103e1724af8'
        self.server = jenkins.Jenkins(jenkins_server_url, username=user_id, password=api_token)

    def get_build_info(self, job_name):
        # job_name = 'TRAIN_UI_ANR'
        last_build_num = self.server.get_job_info(job_name)['lastBuild']['number']
        print(last_build_num)
        # build_info = self.server.get_job_info(job_name)
        build_info = self.server.get_build_info(job_name, last_build_num)
        job_running_list = self.server.get_running_builds()
        print(job_running_list)
        env_vars = self.server.get_build_env_vars(job_name, last_build_num, depth=0)
        print(env_vars)
        return build_info


if __name__ == '__main__':
    print(JenkinsApi().get_build_info('TRAIN_UI_ANR'))
